package com.share.three.b_manual_tx.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import org.springframework.transaction.support.TransactionTemplate;

import com.share.three.b_manual_tx.dao.AccountDaoImpl;


@Service
public class AccountServiceImpl implements AccountService {
	
	@Autowired
	AccountDaoImpl accountDaoImpl;
	
	@Autowired
	TransactionTemplate transactionTemplate;

	@Override
	public void transfer(final String outer, final String inner, final int money) {
		
		transactionTemplate.execute(new TransactionCallbackWithoutResult() {
			@Override
			protected void doInTransactionWithoutResult(TransactionStatus status) {
				accountDaoImpl.out(outer, money);
				int i = 1/0;
				accountDaoImpl.in(inner, money);
			}
		});
	}
}
